<template>
  <div class="mod-oss">
    <el-form :inline="true" :model="dataForm" @submit.native.prevent>
      <el-form-item>
        <el-button type="primary" @click="configHandle()">云存储配置</el-button>
        <el-button type="primary" @click="uploadHandle()">上传文件</el-button>
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">
          批量删除
        </el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" header-align="center" align="center" width="80" label="ID"></el-table-column>
      <el-table-column prop="originalName" header-align="center" align="center" width="80" label="文件名称">
        <template slot-scope="scope">
          <a :href="imageUrl+scope.row.url+ '?token='+token" :download="scope.row.originalName">{{scope.row.originalName}}</a>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" label="图片" width="80px">
        <template slot-scope="scope">
          <el-popover placement="right" title="" trigger="hover">
            <img alt="" :src="imageUrl+scope.row.url+ '?token='+token" style='height: 650px;width: 650px'/>
            <img slot="reference" :src="imageUrl+scope.row.url+ '?token='+token" alt="" style="max-height: 50px;max-width: 50px">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="url" header-align="center" align="center" label="URL地址"></el-table-column>
      <el-table-column prop="createDate" header-align="center" align="center" width="180" label="创建时间"
      ></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="pagination-container" @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 云存储配置 -->
    <config v-if="configVisible" ref="config"></config>
    <!-- 弹窗, 上传文件 -->
    <upload v-if="uploadVisible" ref="upload" @refreshDataList="getDataList"></upload>
  </div>
</template>

<script>
import Config from './oss-config'
import Upload from './oss-upload'
import commonTableMixins from '@/utils/commonTableMixins'

export default {
  mixins: [commonTableMixins],
  data() {
    return {
      dataForm: {},
      configVisible: false,
      uploadVisible: false,
      primaryKey: 'id',
      listApiName: 'systemApi/ossList',
      deleteApiName: 'systemApi/deleteConfig'
    }
  },
  components: {
    Config,
    Upload
  },
  methods: {
    // 云存储配置
    configHandle() {
      this.configVisible = true
      this.$nextTick(() => {
        this.$refs.config.init()
      })
    },
    // 上传文件
    uploadHandle() {
      this.uploadVisible = true
      this.$nextTick(() => {
        this.$refs.upload.init()
      })
    }
  }
}
</script>
